import pygame, sys
from pygame.locals import *
pygame.init()
c = pygame.time.Clock()

screen_width = 640 # this paragraph is just your standard pygame stuff
screen_height = 480
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("TEST")

def get_sprite_width(image): # Finds what the width of the children sprites are
	x, y = 1, 0
	base_color = image.get_at((0,0))
	while y < image.get_height():
		if image.get_at((x, y)) == base_color:
			y += 1
		elif image.get_at((x, y)) != base_color:
			x += 1
	return x+1

def get_images(imgMaster): 
	imgList = []
	offset = 0
	size = (get_sprite_width(imgMaster), imgMaster.get_height()) # Size is the dimensions of the children sprites
	print size[0]
	for i in range(imgMaster.get_width()/size[0]): # Self explanatory
		tmpImg = pygame.Surface(size) # Create a new surface with size
		tmpImg.blit(imgMaster, (0,0), ((offset,0), size)) #blit a piece of the master image onto that surface
		offset += size[0] # Offset to the next piece
		trans = tmpImg.get_at((1,1)) # Setting transparencies
		tmpImg.set_colorkey(trans)
		imgList.append(tmpImg) # Store it. NEXT!
		
	return imgList # Return a list of all stored images
	
master_sprite = pygame.image.load("player.PNG")
sprites = get_images(master_sprite)
i = 0
while True:
	for e in pygame.event.get():
		if e.type is QUIT:
			pygame.quit()
			sys.exit()
			
	screen.fill((255,255,255))
	screen.blit(sprites[i], (0,0))
	
	i += 1
	if i is len(sprites):
		i = 0
		
	pygame.display.flip()
	c.tick(10)